package org.jeecg.common.job;

import org.jeecg.common.job.data.service.IJobService;
import org.jeecg.common.job.data.vo.JobInfoVo;
import org.jeecg.common.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Component("serverMonitor")
public class ServerMonitor {

    private static final Logger LG = LoggerFactory.getLogger("Job");

    @Resource
    private IJobService jobService;

    public void checkServer() {
        this.refreshJob();
    }

    /**
     * 检查任务状态
     */
    private void refreshJob(){
        List<JobInfoVo> jobList = jobService.getCacheSelectJobList();
        JobManageCenter.refreshJob(jobList);
    }

    /**
     * 删除定时任务日志()
     */
    public void deleteJobLogs(){
        // 删除一个月前的数据
        Date date = DateUtil.getDate(-30);
        jobService.deleteLogs(date);
    }
}
